define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user_active/index' + location.search,
                    add_url: 'user_active/add',
                    edit_url: 'user_active/edit',
                    del_url: 'user_active/del',
                    multi_url: 'user_active/multi',
                    import_url: 'user_active/import',
                    table: 'user_active',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'active', title: __('Active'), operate:'BETWEEN'},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"-1":__('Status -1')}, formatter: Table.api.formatter.status},
                        {field: 'weigh', title: __('Weigh'), operate: false},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'user.id', title: __('User.id')},
                        {field: 'user.pid', title: __('User.pid')},
                        {field: 'user.group_id', title: __('User.group_id')},
                        {field: 'user.real_name', title: __('User.real_name'), operate: 'LIKE'},
                        {field: 'user.username', title: __('User.username'), operate: 'LIKE'},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'user.password', title: __('User.password'), operate: 'LIKE'},
                        {field: 'user.pay_password', title: __('User.pay_password'), operate: 'LIKE'},
                        {field: 'user.pay_salt', title: __('User.pay_salt'), operate: 'LIKE'},
                        {field: 'user.salt', title: __('User.salt'), operate: 'LIKE'},
                        {field: 'user.idcard', title: __('User.idcard'), operate: 'LIKE'},
                        {field: 'user.email', title: __('User.email'), operate: 'LIKE'},
                        {field: 'user.mobile', title: __('User.mobile'), operate: 'LIKE'},
                        {field: 'user.avatar', title: __('User.avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'user.level_id', title: __('User.level_id')},
                        {field: 'user.money', title: __('User.money'), operate:'BETWEEN'},
                        {field: 'user.score', title: __('User.score'), operate:'BETWEEN'},
                        {field: 'user.ten_prize_money', title: __('User.ten_prize_money'), operate:'BETWEEN'},
                        {field: 'user.invitation_code', title: __('User.invitation_code'), operate: 'LIKE'},
                        {field: 'user.invitation_num', title: __('User.invitation_num')},
                        {field: 'user.today_active', title: __('User.today_active'), operate:'BETWEEN'},
                        {field: 'user.last_active', title: __('User.last_active'), operate:'BETWEEN'},
                        {field: 'user.is_effect', title: __('User.is_effect')},
                        {field: 'user.effect_user', title: __('User.effect_user')},
                        {field: 'user.prize_total', title: __('User.prize_total')},
                        {field: 'user.alerday_pin_total', title: __('User.alerday_pin_total')},
                        {field: 'user.group_num', title: __('User.group_num')},
                        {field: 'user.group_num_all', title: __('User.group_num_all')},
                        {field: 'user.today_prize', title: __('User.today_prize'), operate:'BETWEEN'},
                        {field: 'user.all_prize', title: __('User.all_prize'), operate:'BETWEEN'},
                        {field: 'user.successions', title: __('User.successions')},
                        {field: 'user.maxsuccessions', title: __('User.maxsuccessions')},
                        {field: 'user.openid', title: __('User.openid'), operate: 'LIKE'},
                        {field: 'user.prevtime', title: __('User.prevtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'user.logintime', title: __('User.logintime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'user.loginip', title: __('User.loginip'), operate: 'LIKE'},
                        {field: 'user.loginfailure', title: __('User.loginfailure')},
                        {field: 'user.status', title: __('User.status'), operate: 'LIKE', formatter: Table.api.formatter.status},
                        {field: 'user.state', title: __('User.state')},
                        {field: 'user.createtime', title: __('User.createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'user.updatetime', title: __('User.updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'user.jointime', title: __('User.jointime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});